local SkillBase = require("gameLogic.fightSkill.show.SkillBase")
local SkillCounterAttack = class("SkillCounterAttack", SkillBase)
local FightConst = require("const.FightConst")
local SkillStrategy = require("gameLogic.fightSkill.strategy.SkillStrategy")
-- 反击技能（装饰者）

local COUNTERATTACK_ID = 9

function SkillCounterAttack:ctor(targetEntity)
    SkillCounterAttack.super.ctor(self)
    self._targetEntity = targetEntity
    local config = require("config.skill_strategy").get(COUNTERATTACK_ID)
    assert(config, "can not found cfg in skill_strategy by id=" .. COUNTERATTACK_ID)
    self._strategy = SkillStrategy.new(self, config)
end

function SkillCounterAttack:getHitTime()
    return 0.2
end

function SkillCounterAttack:attack()
    if not self._targetEntity then
        return
    end
    local goAttackFunc = function()
        self._entity:triggerAnim(self:getSkillAction() .. "Trigger")
    end

    local sequence = DOTween.Sequence()
    local hitTime = self:getHitTime()
    sequence:AppendCallback(goAttackFunc)
    sequence:AppendInterval(hitTime)
    sequence:AppendCallback(
        function()
            self._strategy:doStrategy(self._targetEntity)
        end
    )
end

return SkillCounterAttack
